package com.hanrui.android.fragment.message.audit.proposal;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hanrui.android.R;
import com.hanrui.android.activity.download.MyDownLoadActivity;
import com.hanrui.android.library.base.BaseFragment;
import com.hanrui.android.model.FilesBean;
import com.hanrui.android.model.ProposalDetailBean;
import com.hanrui.android.net.contract.message.audit.proposal.ProposalDetailContract;
import com.hanrui.android.net.presenter.message.audit.proposal.ProposalDetailPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 董事会议案审批基本信息
 *
 */

public class ProposalDetailFragment extends BaseFragment<ProposalDetailPresenter> implements ProposalDetailContract.View {
    @BindView(R.id.main_title)
    TextView mainTitle;
    @BindView(R.id.subhead_title)
    TextView subheadTitle;
    @BindView(R.id.title)
   TextView title;
   @BindView(R.id.name)
   TextView name;
   @BindView(R.id.thing_title)
   TextView thing_title;
   @BindView(R.id.time)
   TextView time;
   @BindView(R.id.leaders)
   TextView leaders;
   @BindView(R.id.enclosure_ll)
   LinearLayout enclosureLl;
   @BindView(R.id.enclosure)
   ImageView enclosure;
   @BindView(R.id.duty_people)
   TextView dutyPeople;
   @BindView(R.id.enclosure_num)
   TextView enclosureNum;


    String taskId,procInsId,bizId;

    List<FilesBean> filesBeanList = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_proposaldetail;
    }

    @Override
    protected void initInjector() { mFragmentComponent.inject(this); }

    @Override
    protected void initView(View view) {

        taskId = getArguments().getString("taskId");
        procInsId = getArguments().getString("procInsId");
        bizId = getArguments().getString("bizId");

        mPresenter.proposalBizDetail(getActivity(),taskId,procInsId,bizId);

    }

    @OnClick({R.id.enclosure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.enclosure:
                MyDownLoadActivity.start(getActivity(),filesBeanList);
                break;
        }
    }

    public static ProposalDetailFragment newInstance(String taskId, String procInsId, String bizId) {
        ProposalDetailFragment fragment = new ProposalDetailFragment();
        Bundle bundle = new Bundle();
        bundle.putString("taskId", taskId);
        bundle.putString("procInsId", procInsId);
        bundle.putString("bizId", bizId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void proposalBizDetail(ProposalDetailBean data) {

        if (null != data) {

            mainTitle.setText("董事会议案");
            title.setText(data.getDetail().getProposal());
            name.setText(data.getDetail().getCondition());
            thing_title.setText(data.getDetail().getShowOfficeName());
            time.setText(data.getDetail().getOfficeName());
            leaders.setText(data.getDetail().getName());

            if (null != data.getFiles() && data.getFiles().size() > 0) {

                enclosureLl.setVisibility(View.VISIBLE);
                filesBeanList.clear();
                filesBeanList.addAll(data.getFiles());
                enclosureNum.setText("["+data.getFiles().size()+"]");

            		}
            dutyPeople.setText(data.getDetail().getRemarks());

        }

    }

}
